package com.easylinkin.linkappapi.investigation.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.investigation.entity.InvestigationTaskModel;
import com.easylinkin.linkappapi.investigation.service.InvestigationTaskModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import java.util.List;

/**
 * <p>
 * 排查任务模板 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2021-04-15
 */
@RestController
@RequestMapping("/investigation/investigationTaskModel")
public class InvestigationTaskModelController {

    @Autowired
    InvestigationTaskModelService service;


    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<InvestigationTaskModel> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<InvestigationTaskModel> record = service.getInvestigationTaskModelPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    @GetMapping("get/{id}")
    public RestMessage get(@PathVariable Long id) {
        Assert.notNull(id, "id 不能为空");
        return RestBuilders.successBuilder().data(service.getInvestigationTaskModel(id)).build();
    }

    @GetMapping("getAll")
    public RestMessage getAll() {
        return RestBuilders.successBuilder().data(service.getInvestigationTaskModelAll()).build();
    }

    @PostMapping("update")
    public RestMessage update(@RequestBody InvestigationTaskModel investigationTaskModel) {
        service.updateInvestigationTaskModel(investigationTaskModel);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("updateStatus")
    public RestMessage updateStauts(@RequestBody InvestigationTaskModel investigationTaskModel) {
        service.updateStatusInvestigationTaskModel(investigationTaskModel);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("add")
    public RestMessage add(@RequestBody InvestigationTaskModel investigationTaskModel) {
        service.addInvestigationTaskModel(investigationTaskModel);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("deleteBatch")
    public RestMessage deleteBatch(@RequestBody List<InvestigationTaskModel> investigationTaskModelList) {
        Assert.notEmpty(investigationTaskModelList, "参数为空");
        service.deleteBatch(investigationTaskModelList);
        return RestBuilders.successBuilder().build();
    }
}
